#include "FreeRTOS.h"
#include "queue.h"
#include "cmsis_os.h"

#include "stm32f411_task_led.h"
#include "stm32f411_task_key.h"
#include "main.h"

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

void led_init(void);
void led_task(void);
void led_on(void);
void led_off(void);
void led_toggle(void);

//初始化结构体
struct LedInterface led_interface = {
    .pfinit = led_init,
    .pftask = led_task,
    .pfon = led_on,
    .pfoff = led_off,
    .pftoggle = led_toggle,
};

void led_init(void){
    led_off();
};
void led_task(void){
    key_result_t key_result;
    xQueueReceive(g_key_result_queue, &key_result, 0);
    if(key_result == KEY_SHORT_PRESS)
    {
        led_toggle();
    }else if(key_result == KEY_LONG_PRESS)
    {
        led_on();
        osDelay(500);
        led_off();
        osDelay(500);

        led_on();
        osDelay(500);
        led_off();
        osDelay(500);

        led_on();
        osDelay(500);
        led_off();
        osDelay(500);
    }else{

    }
};
void led_on(void){
    HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
};
void led_off(void){
    HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
};
void led_toggle(void){
    HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
};
